package com.bjpowernode.utils.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.bjpowernode.config.context.ApplicationContextProvider;
import com.bjpowernode.constant.Constants;
import com.bjpowernode.service.TDicValueService;
import jakarta.annotation.Resource;

import java.util.Map;

/**
 *
 */
public class StateConverter implements Converter<Integer> {

    @Resource
    private TDicValueService tDicValueService;

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 获取spring的bean
        TDicValueService tDicValueService = ApplicationContextProvider.getApplicationContext().getBean(TDicValueService.class);
        // 调用方法 ,获取全部数据
        Map<String, Integer> stringIntegerMap = tDicValueService.selectAllNameAndIdByClueState(Constants.CLUE_STATE);
        // 查询转换数据
        String stringValue = cellData.getStringValue();
        // 转换赋值
        return stringIntegerMap.get(stringValue);
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        /*// 获取所有数据
        Map<Integer , String> stringIntegerMap = tDicValueService.selectAllIdAndNameByTypeCode("clueState");
        // 查询value对应值
        String s = stringIntegerMap.get(value);
        // 返回结果
        return new WriteCellData<>(s);*/
        if (value == 24) {
            return new WriteCellData<>("未联系");
        } else {
            return new WriteCellData<>("将来联系");
        }
    }
}
